# Maintainer: Andreas Kemnade <andreas@kemnade.info>
# Kernel config based on: arch/arm/configs/kobo_defconfig

pkgname=linux-postmarketos-imx-ereader
pkgver=6.11.2
pkgrel=0
pkgdesc="i.MX E-Book reader kernel fork, close to mainline"
replaces="linux-kobo-clara-mainline"
provides="linux-kobo-clara-mainline=$pkgver-r$pkgrel"
arch="armv7"
_carch="arm"
_flavor="postmarketos-imx-ereader"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native pmb:kconfigcheck-nftables"
makedepends="
	bash
	bc
	bison
	devicepkg-dev
	findutils
	flex
	gmp-dev
	lzop
	mpc1-dev
	mpfr-dev
	openssl-dev
	perl
"

# Source
_repository="linux"
_commit="df1ce7a11941cd64297bc861b0aa30e1009c2b80"
_rtl8189fs_repository="rtl8189ES_linux"
_rtl8189fs_commit="9a82349c2c40515f9d20b9f6721670f76b4e1c7a"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/akemnade/$_repository/archive/$_commit.tar.gz
	$_rtl8189fs_repository-$_rtl8189fs_commit.tar.gz::https://github.com/jwrdegoede/$_rtl8189fs_repository/archive/$_rtl8189fs_commit.tar.gz
	$_config
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"
_rtl8189fs_dir="$srcdir/$_rtl8189fs_repository-$_rtl8189fs_commit"

prepare() {
	REPLACE_GCCH=0
	default_prepare
	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$(( pkgrel + 1 ))-postmarketOS"
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$(( pkgrel + 1 ))-postmarketOS" \
		CONFIG_RTW_SDIO_PM_KEEP_POWER=n \
		CONFIG_RTW_DEBUG=n \
		-C "$_rtl8189fs_dir" KSRC="$builddir"
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor" "$_outdir"
	make modules_install dtbs_install \
		O="$_outdir" ARCH="$_carch" \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/boot/dtbs"
	install -Dm644 "$_rtl8189fs_dir"/8189fs.ko "$pkgdir/lib/modules/$(make -s O="$_outdir" ARCH="$_carch" kernelrelease)/kernel/drivers/net/wireless"
}

sha512sums="
7744aa06656d5d5e882323b322f0b94e33a3af8d04a156dd57da2a3e0aea9e9bf29e43b676fa300f2841b7cf50b0b5a14f624abd76582cbca9a77f87bc6471c1  linux-postmarketos-imx-ereader-df1ce7a11941cd64297bc861b0aa30e1009c2b80.tar.gz
f02f35ce3f4b3fc86c867099c04ee0e6755e8eb17e048aba3b8749fe1adb689619cb340724fdb95d395c30dc055846f4e0b170fea6e7c8add2dd5a39ba733104  rtl8189ES_linux-9a82349c2c40515f9d20b9f6721670f76b4e1c7a.tar.gz
f77b4f0ecf0edda7c8b092b2375f92aa4afa0e80056bff6469a31b48942ac213c6f423a799ef6e219385998b512426195cd2969554ba59445925018752f8e84a  config-postmarketos-imx-ereader.armv7
"
